package recharge_channel_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeChannelInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewRechargeChannelInfoLogic 充值渠道--获取一条记录
func NewRechargeChannelInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeChannelInfoLogic {
	return &RechargeChannelInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeChannelInfoLogic) RechargeChannelInfo(req *types.RechargeChannelInfoRequest) (resp *types.RechargeChannelInfoResponse, err error) {
	rpcReq := rpc.RechargeChannelInfoRequest{
		Id: req.Id,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.PayRecharge.RechargeChannelInfo(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	return &types.RechargeChannelInfoResponse{
		Id:           rpcResp.Id,
		CreatedAt:    rpcResp.CreatedAt,
		UpdatedAt:    rpcResp.UpdatedAt,
		DeletedAt:    rpcResp.DeletedAt,
		MappingCode:  rpcResp.MappingCode,
		Type:         rpcResp.Type,
		Name:         rpcResp.Name,
		Level:        rpcResp.Level,
		User_group:   rpcResp.UserGroup,
		BonusRate:    rpcResp.BonusRate,
		MinAmount:    rpcResp.MinAmount,
		MaxAmount:    rpcResp.MaxAmount,
		AmountConfig: rpcResp.AmountConfig,
		MerchantId:   rpcResp.MerchantId,
		AppId:        rpcResp.AppId,
		SecretKey:    rpcResp.SecretKey,
		Url:          rpcResp.Url,
		ReturnUrl:    rpcResp.ReturnUrl,
		NotifyUrl:    rpcResp.NotifyUrl,
		PubKey:       rpcResp.PubKey,
		PrivateKey:   rpcResp.PrivateKey,
		StartTime:    rpcResp.StartTime,
		EndTime:      rpcResp.EndTime,
		Sort:         rpcResp.Sort,
		Status:       rpcResp.Status,
		IsTestable:   rpcResp.IsTestable,
		WhiteList:    rpcResp.WhiteList,
		Remark:       rpcResp.Remark,
		Icon:         rpcResp.Icon,
		ChannelName:  rpcResp.ChannelName,
		INR:          rpcResp.Inr,
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
